<?php
defined('IN_MAIN') or exit('Invalid Access!');

function calc_personal_sales($uid, $date_from, $date_to){
/*
This function calculate the total sales volume for the input uid for the date range date_from to date_to
*/

	global $vars;
	$db=$vars["db"];
	
	$calc_date['start'] = date("Y-m-d H:i:s", strtotime('2013-01-01 00:00:00'));
	$calc_date['end'] = date("Y-m-d H:i:s", strtotime('2020-12-31 23:59:59'));
	
	$total_sale = @mysql_result(mysql_query("select sum(a.total_bv) from $db->purchase a inner join $db->users s on s.id='$uid' inner join $db->users d on d.id=a.uid and d.ref_left between s.ref_left and s.ref_right where a.status='confirmed' and a.cdate>='$calc_date[start]' and a.cdate<='$calc_date[end]'"), 0) or 0;
				
	return $total_sale;
}
?>